home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11tl.lha / lbl / xview / xhist / label.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-09-17  |  7.3 KB  |  429 lines

  1.  
  2. #include <stdio.h>
  3.  
  4. #include <math.h>
  5.  
  6. extern int y_label[10];
  7.  
  8. extern int end_y;        /* end of y_label[]        */
  9.  
  10. extern int x_label[20];
  11.  
  12. extern int end_x;        /* end of x_label[]        */
  13.  
  14. extern float fx_label[20];
  15.  
  16. extern float fy_label[20];
  17.  
  18. int       nece[20];        /* necessary label         */
  19.  
  20. int       end_nece;        /* end of nece[]         */
  21.  
  22. float     fnece[20];        /* necessary label         */
  23.  
  24.  
  25. build_xlab(Low, High)        /* build int x label     */
  26.     int       Low, High;
  27. {
  28.     int       i;
  29.  
  30.     if (Low >= 0 && High >= 0) {
  31.     if (High - Low > 10) {
  32.         build_label(Low, High);
  33.         for (i = 0; i < end_y; i++)
  34.         x_label[i] = y_label[i];
  35.         end_x = end_y;
  36.     } else if (High - Low > 4) {
  37.         x_label[0] = Low;
  38.         x_label[1] = (High + Low) / 4;
  39.         x_label[2] = (High + Low) / 2;
  40.         x_label[3] = (High + Low) * 3 / 4;
  41.         x_label[4] = High;
  42.         end_x = 5;
  43.     } else if (High - Low > 1) {
  44.         x_label[0] = Low;
  45.         x_label[1] = (High + Low) / 2;
  46.         x_label[2] = High;
  47.         end_x = 3;
  48.     } else {
  49.         x_label[0] = Low;
  50.         x_label[1] = High;
  51.         end_x = 2;
  52.     }
  53.  
  54.     return;
  55.     }
  56.     if (Low < 0 && High >= 0) {
  57.     if (Low < -10) {
  58.         build_label(0, -Low);
  59.         for (i = 0; i < end_y - 1; i++)
  60.         x_label[i] = -y_label[end_y - 1 - i];
  61.         x_label[end_y - 1] = 0;
  62.         end_x = end_y;
  63.     } else {
  64.         x_label[0] = Low;
  65.         x_label[1] = 0;
  66.         end_x = 2;
  67.     }
  68.  
  69.     if (10 < High) {
  70.         build_label(0, High);
  71.         for (i = 1; i < end_y; i++)
  72.         x_label[end_x - 1 + i] = y_label[i];
  73.         end_x = end_x - 1 + end_y;
  74.     } else {
  75.         x_label[end_x] = High;
  76.         end_x++;
  77.     }
  78.  
  79.     return;
  80.     }
  81.     /* Low<0 && High<0   */
  82.     if (High - Low > 10) {
  83.     build_label(-High, -Low);
  84.     for (i = 0; i < end_y; i++)
  85.         x_label[i] = -y_label[end_y - 1 - i];
  86.     end_x = end_y;
  87.     } else if (High - Low > 1) {
  88.     x_label[0] = Low;
  89.     x_label[1] = (High + Low) / 2;
  90.     x_label[2] = High;
  91.     end_x = 3;
  92.     } else {
  93.     x_label[0] = Low;
  94.     x_label[1] = High;
  95.     end_x = 2;
  96.     }
  97.  
  98. }                /* end of build_xlab (Low, High)    */
  99.  
  100.  
  101. build_label(Low, High)
  102.     int       Low, High;    /* positive integers and High - Low > 10     */
  103. {
  104.     int       p;
  105.     int       q;
  106.     int       InLab;
  107.     int       interior[20];
  108.     int       k;
  109.     int       j;
  110.     int       unit;        /* unit=1, 2, 3, 4         */
  111.  
  112. #ifdef aax
  113.     printf("enter build_label, Low=%d  High=%d\n", Low, High);
  114. #endif
  115.  
  116.     y_label[0] = Low;
  117.  
  118.     if (High - Low <= 30) {
  119.     end_y = 1;
  120.     for (j = Low + 1; j < High; j++)
  121.         if (j % 10 == 0) {
  122.         y_label[end_y] = j;
  123.         end_y++;
  124.         }
  125.     y_label[end_y] = High;
  126.     end_y++;
  127.     return;
  128.     }
  129.     p = log10((double) High);
  130.     q = exp10((double) p);
  131.  
  132.     end_nece = 0;        /* end of nece[]                */
  133.  
  134. next_:
  135.  
  136.     InLab = ((Low + q) / q) * q;
  137.  
  138.     k = 0;
  139.  
  140.     while (Low < InLab && InLab < High) {
  141.     interior[k] = InLab;
  142.     k++;
  143.     InLab = InLab + q;
  144.     }
  145.  
  146.     switch (k) {
  147.     case 0:
  148.     q = q / 10;
  149.     goto next_;
  150.     case 1:
  151.     nece[end_nece] = interior[0];
  152.     end_nece++;
  153.     if (q == (q / 40) * 40)
  154.         q = q / 4;
  155.     else
  156.         q = q / 10;
  157.     goto next_;
  158.     case 2:
  159.     nece[end_nece] = interior[0];
  160.     end_nece++;
  161.     nece[end_nece] = interior[1];
  162.     end_nece++;
  163.     q = q / 2;
  164.     goto next_;
  165.     case 3:
  166.     case 4:
  167.     case 5:
  168.     unit = 1;
  169.     break;
  170.     case 6:
  171.     case 7:
  172.     case 8:
  173.     case 9:
  174.     unit = 2;
  175.     break;
  176.     case 10:
  177.     case 11:
  178.     case 12:
  179.     case 13:
  180.     case 14:
  181.     unit = 3;
  182.     break;
  183.     default:
  184.     unit = 4;
  185.     break;
  186.     }
  187.  
  188.     end_y = 1;
  189.  
  190.     for (j = 0; j < end_nece; j++) {
  191.     if (end_y > 6)
  192.         break;
  193.     else
  194.         add_lab(nece[j]);
  195.     }
  196.  
  197.     for (j = k / 2; j < k; j = j + unit) {
  198.     if (end_y > 6)
  199.         break;
  200.     else
  201.         add_lab(interior[j]);
  202.     }
  203.  
  204.     for (j = k / 2 - unit; j >= 0; j = j - unit) {
  205.     if (end_y > 6)
  206.         break;
  207.     else
  208.         add_lab(interior[j]);
  209.     }
  210.  
  211.     y_label[end_y] = High;
  212.  
  213.     end_y++;            /* outside         */
  214.  
  215. }                /* end of build_label (Low, High)     */
  216.  
  217. add_lab(val)            /* add label         */
  218.     int       val;
  219. {
  220.     int       i;
  221.  
  222.     for (i = 1; i < end_y; i++)
  223.     if (val == y_label[i])
  224.         return;
  225.  
  226.     y_label[end_y] = val;
  227.  
  228.     end_y++;            /* outside          */
  229. }
  230.  
  231. /*  The following are for float.        */
  232.  
  233. build_fxlab(Low, High)        /* build int x label     */
  234.     float     Low, High;
  235. {
  236.     int       i;
  237.  
  238.     if (Low >= 0. && High >= 0.) {
  239.     if (High - Low > 10.) {
  240.         bd_fy(Low, High);
  241.         for (i = 0; i < end_y; i++)
  242.         fx_label[i] = fy_label[i];
  243.         end_x = end_y;
  244.     } else {
  245.         fx_label[0] = Low;
  246.         fx_label[1] = (High + Low) / 4;
  247.         fx_label[2] = (High + Low) / 2;
  248.         fx_label[3] = (High + Low) * 3 / 4;
  249.         fx_label[4] = High;
  250.         end_x = 5;
  251.     }
  252.  
  253.     return;
  254.     }
  255.     if (Low < 0. && High >= 0.) {
  256.     if (Low < -10.) {
  257.         bd_fy(0., -Low);
  258.         for (i = 0; i < end_y - 1; i++)
  259.         fx_label[i] = -fy_label[end_y - 1 - i];
  260.         fx_label[end_y - 1] = 0.;
  261.         end_x = end_y;
  262.     } else {
  263.         fx_label[0] = Low;
  264.         fx_label[1] = 0.;
  265.         end_x = 2;
  266.     }
  267.  
  268.     if (10. < High) {
  269.         bd_fy(0., High);
  270.         for (i = 1; i < end_y; i++)
  271.         fx_label[end_x - 1 + i] = fy_label[i];
  272.         end_x = end_x - 1 + end_y;
  273.     } else {
  274.         fx_label[end_x] = High;
  275.         end_x++;
  276.     }
  277.  
  278.     return;
  279.     }
  280.     /* Low<0 && High<0   */
  281.     if (High - Low > 10.) {
  282.     bd_fy(-High, -Low);
  283.     for (i = 0; i < end_y; i++)
  284.         fx_label[i] = -fy_label[end_y - 1 - i];
  285.     end_x = end_y;
  286.     } else if (High - Low > 1.) {
  287.     fx_label[0] = Low;
  288.     fx_label[1] = (High + Low) / 2;
  289.     fx_label[2] = High;
  290.     end_x = 3;
  291.     } else {
  292.     fx_label[0] = Low;
  293.     fx_label[1] = High;
  294.     end_x = 2;
  295.     }
  296.  
  297. }                /* end of build_fxlab (Low, High)    */
  298.  
  299.  
  300. bd_fy(Low, High)
  301.     float     Low, High;    /* positive integers and High - Low > 10     */
  302. {
  303.     int       p;
  304.     float     q;
  305.     float     InLab;
  306.     float     interior[20];
  307.     int       k;
  308.     int       j;
  309.     int       unit;        /* unit=1, 2, 3, 4         */
  310.  
  311. #ifdef aax
  312.     printf("enter bd_fy, Low=%.2f  High=%.2f\n", Low, High);
  313. #endif
  314.  
  315.     fy_label[0] = Low;
  316.  
  317.     if (High - Low <= 30.) {
  318.     end_y = 1;
  319.     for (j = Low + 1; j < High; j++)
  320.         if (j % 10 == 0) {
  321.         fy_label[end_y] = j;
  322.         end_y++;
  323.         }
  324.     fy_label[end_y] = High;
  325.     end_y++;
  326.     return;
  327.     }
  328.     p = log10((double) High);
  329.     q = exp10((double) p);
  330.  
  331.     end_nece = 0;        /* end of fnece[]                */
  332.  
  333. next_:
  334.  
  335.     InLab = floor((Low + q) / q) * q;
  336.  
  337.     k = 0;
  338.  
  339.     while (Low < InLab && InLab < High) {
  340.     interior[k] = InLab;
  341.     k++;
  342.     InLab = InLab + q;
  343.     }
  344.  
  345.     switch (k) {
  346.     case 0:
  347.     q = q / 10;
  348.     goto next_;
  349.     case 1:
  350.     fnece[end_nece] = interior[0];
  351.     end_nece++;
  352.     if (q == floor(q / 40.) * 40.)
  353.         q = q / 4;
  354.     else
  355.         q = q / 10;
  356.     goto next_;
  357.     case 2:
  358.     fnece[end_nece] = interior[0];
  359.     end_nece++;
  360.     fnece[end_nece] = interior[1];
  361.     end_nece++;
  362.     q = q / 2;
  363.     goto next_;
  364.     case 3:
  365.     case 4:
  366.     case 5:
  367.     unit = 1;
  368.     break;
  369.     case 6:
  370.     case 7:
  371.     case 8:
  372.     case 9:
  373.     unit = 2;
  374.     break;
  375.     case 10:
  376.     case 11:
  377.     case 12:
  378.     case 13:
  379.     case 14:
  380.     unit = 3;
  381.     break;
  382.     default:
  383.     unit = 4;
  384.     break;
  385.     }
  386.  
  387.     end_y = 1;
  388.  
  389.     for (j = 0; j < end_nece; j++) {
  390.     if (end_y > 6)
  391.         break;
  392.     else
  393.         add_flab(fnece[j]);
  394.     }
  395.  
  396.     for (j = k / 2; j < k; j = j + unit) {
  397.     if (end_y > 6)
  398.         break;
  399.     else
  400.         add_flab(interior[j]);
  401.     }
  402.  
  403.     for (j = k / 2 - unit; j >= 0; j = j - unit) {
  404.     if (end_y > 6)
  405.         break;
  406.     else
  407.         add_flab(interior[j]);
  408.     }
  409.  
  410.     fy_label[end_y] = High;
  411.  
  412.     end_y++;            /* outside         */
  413.  
  414. }                /* end of bd_fy (Low, High)     */
  415.  
  416. add_flab(val)            /* add label         */
  417.     float     val;
  418. {
  419.     int       i;
  420.  
  421.     for (i = 1; i < end_y; i++)
  422.     if (val == fy_label[i])
  423.         return;
  424.  
  425.     fy_label[end_y] = val;
  426.  
  427.     end_y++;            /* outside          */
  428. }
  429.